/***
 * Copyright (c) 2004 Sagem Monetel SA, rue claude Chappe,
 * 07503 Guilherand-Granges, France, All Rights Reserved.
 *
 * Sagem Monetel SA has intellectual property rights relating
 * to the technology embodied in this software.  In particular, 
 * and without limitation, these intellectual property rights 
 * may include one or more patents.
 *
 * This software is distributed under licenses restricting 
 * its use, copying, distribution, and decompilation.  
 * No part of this software may be reproduced in any form 
 * by any means without prior written authorization of 
 * Sagem Monetel.
 *
 * @Title:        
 * @Description: SDK30 sample application 
 * @Reference:    
 * @Comment:      
 *
 * @author        
 * @version       
 * @Comment:      
 * @date:         
 */
#include "SDK30.H"
#include "etat.h"
//#define APP_ECR

extern void xx_print(char buffer);
//extern void _trace(const char * format,...);
extern int after_reset         (NO_SEGMENT, void *,        S_TRANSOUT *);
extern void StateHeaders(int st);
extern void _trace(const char * format,...);

int Main(unsigned int size, StructPt *data)
{
	NO_SEGMENT No;
	int            ret;
	//pp_open_hmi();
	//pp_close_hmi();
	
	No = ApplicationGetCurrent();
	StateHeaders(0);

	switch(data->service)
	{
	case AFTER_RESET :
		_trace("AFTER_RESET");
		ret = after_reset(No,NULL,&data->Param.AfterReset.param_out);
        break;

	case MORE_FUNCTION :
		_trace("MORE_FUNCTION");

		ret = more_function(No,NULL,NULL);
        break;

	case IS_TIME_FUNCTION :
		_trace("IS_TIME_FUNCTION");
		ret = is_time_function(No,NULL,&data->Param.IsTimeFunction.param_out); 
	break;

	case TIME_FUNCTION :
		_trace("TIME_FUNCTION");
       	 ret = time_function(No,NULL,NULL); 
	break;

	case CONSULT :
		_trace("CONSULT");
		ret = consult(No,NULL,NULL);
        break;

	case MCALL :
		_trace("MCALL");
		ret = mcall(No,NULL,NULL);
        break;

	case STATE :
		_trace("STATE");
		ret = state(No,NULL,NULL);
        break;

	case IS_NAME :
		_trace("IS_NAME");
		ret = is_name(No,NULL,&data->Param.IsName.param_out);
        break;

	case IS_STATE :
		_trace("IS_STATE");
		ret = is_state(No,NULL,&data->Param.IsState.param_out);
        break;

	case IS_EVOL_PG :
		_trace("IS_EVOL_PG");
		ret = is_evol_pg(No,NULL,&data->Param.IsEvolPg.param_out);
        break;

	case IS_CHANGE_INIT :
		_trace("IS_CHANGE_INIT");
        ret = is_change_init(No,NULL,&data->Param.IsChangeInit.param_out);
        break;

	case MODIF_PARAM :
		_trace("MODIF_PARAM");
        ret = modif_param(No, &data->Param.ModifParam.param_in, NULL);
		break;

	case IDLE_MESSAGE :
		_trace("IS_TIME_FUNCTION");
        	idle_message(No,NULL,NULL);
        break;

	case KEYBOARD_EVENT :
		_trace("KEYBOARD_EVENT");
        ret = keyboard_event(No,&data->Param.KeyboardEvent.param_in,&data->Param.KeyboardEvent.param_out);
		break;

	case FILE_RECEIVED :
		_trace("FILE_RECEIVED");
        	ret = file_received(No,&data->Param.FileReceived.param_in,NULL);
        break;

	case IS_FOR_YOU_AFTER : 
		_trace("IS_FOR_YOU_AFTER");
		ret = is_for_you_after(No,&data->Param.IsForYouAfter.param_in,&data->Param.IsForYouAfter.param_out);
        break;

	case IS_DELETE :
		_trace("IS_DELETE");
        	ret = is_delete(No,NULL,&data->Param.IsDelete.param_out);
        break;

	case DEBIT_NON_EMV :
		_trace("DEBIT_NON_EMV");
		ret = debit_non_emv(No,&data->Param.DebitNonEmv.param_in,&data->Param.DebitNonEmv.param_out);
        break;
		
	case GIVE_YOUR_DOMAIN :
		//_trace("GIVE_YOUR_DOMAIN");
		ret = give_your_domain(No,NULL,&data->Param.GiveYourType.param_out);
        break;

	 case SELECT_AID_EXTENDED:
	 	_trace("SELECT_AID_EXTENDED");
          //  ret=select_aid_extended((unsigned char)No, &data->Param.SelectAidExtended.param_in, &data->Param.SelectAidExtended.param_out);
           break;
			
        case SELECT_AID:
			_trace("SELECT_AID");
          //  ret=select_aid((unsigned char)No, &data->Param.SelectAid.param_in,&data->Param.SelectAid.param_out);
        break;
	case FALL_BACK:
		_trace("FALL_BACK");
	//	ret=fall_back((unsigned char)No, (S_TRANSIN*)&data->Param.FallBack.param_in,NULL);
	break;
	case TIME_FUNCTION_CHAINE : // French Bank Domain 
	case GIVE_INFOS_CX:		// French Bank Domain 
	 
	case DEBIT_OVER:
	case AUTO_OVER:
	case IS_ORDER:			// French Health Care Domain 
	case ORDER:				// French Health Care Domain 
	case IS_SUPPR_PG:		// French Health Care Domain 
	case IS_INSTALL_PG:		// French Health Care Domain 
	case GET_ORDER:			// French Health Care Domain 
	case IS_LIBELLE:		// French Health Care Domain 
	case EVOL_CONFIG:		// French Bank Domain 
	case GIVE_MONEY:		// French Bank Domain 
	//	case COM_EVENT:
#ifdef APP_ECR
	case COM_EVENT:	
		ret=com_event((unsigned char)No, (S_COMIN *)&data->Param.ComEvent.param_in, ( S_COMOUT  *)&data->Param.ComEvent.param_out);
		break;
#endif
	case MODEM_EVENT:
	case MESSAGE_RECEIVED:
	case CARD_INSIDE:		// French Health Care Domain
	case GIVE_INTERFACE: 
	case IS_BIN_CB:			// French Bank Domain
	case IS_CARD_SPECIFIC: // French Health Care Domain
	case GIVE_AID:
		break;
	case IS_FOR_YOU_BEFORE : 
		_trace("IS_FOR_YOU_BEFORE");
	//	ret = is_for_you_before(No,&data->Param.IsForYouBefore.param_in,&data->Param.IsForYouBefore.param_out);
		break;
	case IS_CARD_EMV_FOR_YOU:
	//case DEBIT_EMV:
	case SELECT_FUNCTION:		// French Bank Domain
	case SELECT_FUNCTION_EMV:	// French Bank Domain
	default:
        break;
	}

	return FCT_OK;
}

